package com.doyens.gmall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.doyens.gmall.common.result.Result;
import com.doyens.gmall.model.product.SkuInfo;
import com.doyens.gmall.product.service.SkuManageService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "sku商品信息接口")
@RestController
@RequestMapping("admin/product")
public class SkuManageController {

    @Autowired
    private SkuManageService skuManageService;

    @PostMapping("savaSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        System.out.println("savaSkuInfo");
        skuManageService.saveSkuInfo(skuInfo);
        return Result.ok();
    }

    @GetMapping("list/{page}/{limit}")
    public Result index(@PathVariable("page") Long page,@PathVariable("limit") Long limit){
        IPage<SkuInfo> skuInfoIPage = skuManageService.getPage(page,limit);
        return Result.ok(skuInfoIPage);

    }

    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable("skuId") Long skuId){
        skuManageService.onSale(skuId);
        return Result.ok();
    }

    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId){
        skuManageService.cancelSale(skuId);
        return Result.ok();
    }



}
